package com.allinpay;

import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-1-26
 * <p>Version: 1.0
 * 一般来说都是通过rbac 来进行授权, 用shiro 授权????
 *
 */
public class AuthorizerTest extends BaseTest {

    private final static Log log = LogFactory.getLog(AuthorizerTest.class);
    @Test
    public void testIsPermitted() {
        super.login("classpath:shiro-authorizer.ini", "zhang", "123");
        //判断拥有权限：user:create
        log.info(getSubject().isPermitted("user1:update"));
        log.info(getSubject().isPermitted("user2:update"));
        //通过二进制位的方式表示权限
        log.info(getSubject().isPermitted("+user1+2"));//新增权限
        log.info(getSubject().isPermitted("+user1+8"));//查看权限
        log.info(getSubject().isPermitted("+user2+10"));//新增及查看

        Assert.assertFalse(getSubject().isPermitted("+user1+4"));//没有删除权限

        log.info(getSubject().isPermitted("menu:view"));//通过MyRolePermissionResolver解析得到的权限
    }

    @Test
    public void testIsPermitted2() {
        login("classpath:shiro-jdbc-authorizer.ini", "zhang", "123");
        //判断拥有权限：user:create
        log.info(getSubject().isPermitted("user1:update"));
        log.info(getSubject().isPermitted("user2:update"));
        //通过二进制位的方式表示权限
        log.info(getSubject().isPermitted("+user1+2"));//新增权限
        log.info(getSubject().isPermitted("+user1+8"));//查看权限
        log.info(getSubject().isPermitted("+user2+10"));//新增及查看

        log.info(getSubject().isPermitted("+user1+4"));//没有删除权限

        log.info(getSubject().isPermitted("menu:view"));//通过MyRolePermissionResolver解析得到的权限
    }






}
